package net.love5z.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.love5z.web.service.TestService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class TestController {

    @Autowired
    private TestService testService;

    @RequestMapping(value = "/m/{greet}", method = RequestMethod.GET)
    public String index(@PathVariable("greet")
    String greet, ModelMap map, HttpServletRequest request, HttpServletResponse response) {
        map.addAttribute("greet", greet);
        map.addAttribute("time", testService.test());
        return "test.vm";
    }

    @RequestMapping(value = "/login/{user}", method = RequestMethod.GET)
    public String user(@PathVariable("user")
    String user, ModelMap map, HttpServletRequest request, HttpServletResponse response) {
        map.addAttribute("greet", "Hello World!");
        map.addAttribute("user", user);
        return "user.vm";
    }

}
